export class FileItem{
  private _name: string
  private _update_ts: Date

  public constructor(name: string){
    this._name = name
    this._update_ts = new Date()
  }

  public get name(): string{
    return this._name 
  }
  public get update_ts(): Date {
    return this._update_ts
  }

  public refresh(): void {
    this._update_ts = new Date()
  }

  public getRefreshTimestamp(): string {
    return this._update_ts.toLocaleTimeString()
  }


}


export class WebFileItem extends FileItem{
  private _url: string

  public constructor(name: string, url:string){
    super(name)
    this._url = url
  }

  public get url(): string{
    return this._url
  }
}




export class FileItemResult {
  private _is_visible: boolean
  private _webFileItem: WebFileItem

  public static from(name: string, url: string, is_visible: boolean = true) {
    return new FileItemResult(name, url, is_visible);
  }

  public constructor(name:string, url:string, is_visible: boolean) {
    this._webFileItem = new WebFileItem(name, url);
    this._is_visible = is_visible;
  }

  public get name(): string {
    return this._webFileItem.name;
  }
  public get url(): string {
    return this._webFileItem.url;
  }
  public getRefreshTimestamp() : string {
    return this._webFileItem.getRefreshTimestamp();
  }

  public refresh() : void {
    this._webFileItem.refresh()
  }

  public get isVisible(): boolean {
    return this._is_visible;
  }

  public set isVisible(v: boolean):void {
    this._is_visible = v;
  }
  public show(): void {
    this.isVisible = true;
  }
  public hide(): void {
    this.isVisible = false;
  }
}



export class FileItemResults {
  private _files: FileItemResult [];

  public constructor(){
    this._files = []
  }

  public get items(): FileItemResult [] {
    return this._files
  }
  public get length() {
    return this._files.length;
  }

  public push(fi: FileItemResult) : boolean {
    this._files.push(fi)
    return true;
  }
  public pop(): [boolean, FileItemResult] {
    if(this.length > 0){
      return [true, this._files.pop()]
    }
    return [false, null]
  }


  //[ok, isVisible]
  public getItemVisible(index: number): [boolean, boolean] {
    if(index >= 0 && index < this.length ){
      return [true, this._files[index].isVisible]
    }
    return [false, null]
  }
  public showItem(index: number): boolean {
    if(index >= 0 && index < this.length ){
      this._files[index].show()
      return true
    }
    return false
  }
  public hideItem(index: number): boolean {
    if(index >= 0 && index < this.length ){
      this._files[index].hide()
      return true
    }
    return false
  }

  //show all items
  public show(): void{
    this._files.forEach((f) => f.show())
  }
  //hide all items
  public hide(): void{
    this._files.forEach((f) =>  f.hide())
  }
  // means is all visiable 
  public isVisible(): boolean {
    return this._files.every((f) => (f.isVisible == true))
  }
  //means is all hidden
  public isHidden(): boolean {
    return this._files.every((f) => (f.isVisible == false))
  }
}





